﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "HJSP";
}
<div>
    <fieldset class="boun" style="height:70px;">
        <legend class="len">功能键</legend>
        <div style="text-align:right;padding-right:4%">
            <input type="button" name="name" value="物料成本" id="WLcb" />
            <input type="button" name="name" value="返回" id="fanghui" />
            <input type="button" name="name" value="通过" id="dabiO1" />
            <input type="button" name="name" value="驳回" id="dabiOLP" />
        </div>
    </fieldset>
</div>
<div class="Zhuyags">
    <div class="col-2 nav-item" id="divjibeng">@Resource.String48</div>
    <div class="col-2 nav-item" id="divbeizhu">@Resource.String49</div>
    <div class="col-2 nav-item" id="divtuzhi">@Resource.String50</div>
    <div class="col-2 nav-item" id="divweituo" style="display:none">@Resource.String51</div>
</div>
<div id="WT_dh_mb2" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:200px;width:300px">
    <div style="text-align: right; background-color: #84acde;"><span class="WT_qxbh2" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
    <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
        <div id="WJ_XZLJ"></div>
    </div>
    <div style="text-align:center"><button class="WT_qxbh2">@Resource.String126</button></div>
</div>
<div>
    <div id="divsw1">
        <fieldset class="boun">
            <legend class="len">申请单信息</legend>
            <div>
                <table id="BiaoTo" class="table-app">
                    @foreach (var item in ViewBag.APPH as List<Applications>)
                    {
                        <tr style="display:none" id="HUSNA"><td>@(Session["jisn"])</td><td id="JNKMHNB">@item.AP_ren</td></tr>
                        <tr>
                            <td>@Resource.String429</td>
                            <td>
                                <input type="text" id="txtname" name="dan" readonly="readonly" value="@item.App_Kehu">
                            </td>
                            <td>@Resource.String430</td>
                            <td>
                                <input type="text" id="txtdan" name="dan" readonly="readonly" value="@(Session["bians"])">
                            </td>
                        </tr>
                        <tr>
                            <td>@Resource.String431</td>
                            <td>
                                <input type="datetime" id="txtqishi" name="qishi" readonly="readonly" value="@item.App_qishi">
                            </td>

                            <td>@Resource.String432</td>
                            <td>
                                <input type="datetime" id="txtjeishu" name="jeishu" readonly="readonly" value="@item.App_JTime">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                @Html.Label(Resource.String433):
                            </td>
                            <td>
                                <label id="hsijddd"> @item.APP_name</label>
                            </td>
                            <td>@Html.Label(Resource.String435):</td>
                            <td> @item.APP_Zhong</td>
                        </tr>
                        <tr>
                            <td>@Html.Label(Resource.String437):</td>
                            <td> @item.App_dizhi</td>
                            <td>@Html.Label(Resource.String434): </td>
                            <td>@item.App_lei</td>
                        </tr>
                        <tr>
                            <td>@Html.Label(Resource.String438):</td>
                            <td> @item.App_sho</td>
                            <td>
                                @Html.Label(@Resource.String77):
                            </td>
                            <td>
                                <lable id="Shenji">@item.APP_she</lable>
                            </td>
                        </tr>
                    }

                </table>
            </div>
        </fieldset>
    </div>
    <div id="divsw2" style="display:none">
        <div id="bigbox1">
            <fieldset class="boun" id="boun" style="height:150px">
                <legend class="len">@Resource.String558</legend>
                <div id="RZ_gwzr" class="beizhugun">

                </div>
            </fieldset>
        </div>
        <div class="">
            <fieldset class="boun">
                <legend class="len">@Resource.String83</legend>
                <div id="div2_div">
                </div>
                <textarea rows="4" class="col-11" id="RZ_xznr"></textarea><br />
                <input type="button" name="name" value="@Resource.tj" id="RZ_tjrz" />
            </fieldset>
        </div>
    </div>
    @*图纸备注*@
    <div id="divsw3" style="display:none">
        <div class="">
            <fieldset class="boun">
                <legend class="len">@Resource.String84</legend>
                <table class="table tab">
                    <thead style="text-align:center;">
                        <tr style="background-color: #6e95bc">
                            <td>@Resource.String85</td>
                            <td>@Resource.String86</td>
                            <td>@Resource.String87</td>
                            <td>@Resource.String88</td>
                            <td>@Resource.String89</td>
                        </tr>
                    </thead>
                    <tbody id="div3__tb">
                    </tbody>
                </table>
            </fieldset>
        </div>
    </div>
</div>
<div>
    <table class="table table-sm gun">
        <thead class="thead-light">
            <tr>
                <th colspan="7" style="text-align:center">所有物料信息</th>
            </tr>
            <tr>
                <th>物料信息</th>
                <th>层级</th>
                <th>料号</th>
                <th>规格</th>
                <th>一级类别</th>
                <th>二级类别</th>
                <th>类型</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody id="BOMEi">
        </tbody>
    </table>
</div>
<fieldset>
    <div id="Kngsjh">

    </div>
</fieldset>
<div id="WT_dh_mb" class="BoHuiJM">
    <div id="WJ_ID" style="display:none"></div>
    <div class="se-lightblue"><p>驳回</p></div>
    <table class="table-sm table-light">
        <tr>
            <td>@Resource.String501：</td>
            <td id="WT_dhr"></td>
        </tr>
        <tr>
            <td>@Resource.String502</td>
            <td><textarea id="WT_dhly"></textarea></td>
        </tr>
    </table>
    <div class="dui se-lightblue">
        <button id="WT_qdbh">@Resource.String503</button>
        <button id="WT_qxbh">@Resource.String504</button>
    </div>
</div>

<div id="show_shangc" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:400px;width:600px">
    <div style="text-align: right; background-color: #84acde;"><span class="QUED_quxiao" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
    <div class="row">
        <div class="col-lg-2" id="clfl">材料/辅料</div>
        <div class="col-lg-2" id="gyqt">工艺/其他</div>
    </div>
    <div style="margin: 20px 10px; padding: 10px; background-color: #fff; ">
        <div style="display:block" id="clfl_2">
            <table class="table tab">
                <thead class="thead-light">
                    <tr style="text-align-last:center;">
                        <td>材料名</td>
                        <td>规格</td>
                        <td>使用数量</td>
                        <td>价格</td>
                    </tr>
                </thead>
                <tbody id="wlxi">
                </tbody>
            </table>
        </div>
        <div style="display:none" id="gyqt_2">
            <table class="table tab">
                <thead class="thead-light">
                    <tr style="text-align-last:center;">
                        <td>工艺名</td>
                        <td>规格</td>
                        <td>价格</td>
                        <td>备注</td>
                    </tr>
                </thead>
                <tbody id="gyqt_JI">
                </tbody>
            </table>
        </div>
    </div>
    <div style="text-align:center"><button class="QUED_quxiao">@Resource.String126</button></div>
</div>

@section scripts{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li11").css({ "color": "black", "background-color": "white" })
            var bain = $("#txtdan").val()


            $(document).on("click", "#clfl", function () {
                $("#clfl_2").css({ display: "block" })
                $("#gyqt_2").css({ display: "none" })
            })
            $(document).on("click", "#gyqt", function () {
                $("#clfl_2").css({ display: "none" })
                $("#gyqt_2").css({ display: "block" })
            })
            function find_bom() {
                $.ajax({
                    url: '/ShenPI/HJSP',
                    type: 'GET',
                    data: { "Bians": bain, "state": 5 },
                    success: function (data) {
                        $("#BOMEi tr").remove()
                        $.each(data, function (i, item) {
                            var temp7 = item.BOM2_Sone
                            temp7 = temp7 == "1" ? "纸质" : temp7 == "2" ? "木质" : temp7 == "3" ? "塑料" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7 == "8" ? "套件" : temp7;
                            var $tr =
                                $(`<tr>
                                    <th style="display:none">${item.BOM2_id}</th>
                                        <th>${item.BOM2_wuLiu}</th>
                                        <th>${item.BOM2_chen}</th>
                                        <th>${item.BOM2_liao}</th>
                                        <th>${item.BOM2_Guige}</th>
                                        <th>${temp7}</th>
                                        <th>${item.BOM2_ST}</th>
                                        <th>${item.BOM2_Lei}</th>
                                        <th><a href="#" id="ckancc">查看组成</a></th>
                                    </tr>`)
                            $("#BOMEi").append($tr)
                        })
                    },
                    error: function () {
                        alert('Request Error')
                    }
                })
            }
            $(document).on("click", "#ckancc", function (e) {
                var name = $(e.target).parent().parent().children().eq(0).text()
                var bain = $("#txtdan").val()
                $.ajax({
                    url: '/ShenPI/HJSP',
                    type: 'POST',
                    data: { "state": 6, "Bians": name },
                    success: function (data) {
                        if (data == "该行不存在") {
                            alert(data + "工艺未配置或该BOM含子项！")
                        } else {
                            window.location.href = "/Material/Index?names=" + bain + "&bid=" + name + "&fro=HJSP";
                        }
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })

            })
            $(document).on("click", ".QUED_quxiao", function () {
                $("#show_shangc").css({ "display": "none" })
            })
            //find_SZBZ()
            find_bom()
            find_inf()
            //搜索根据申请单号搜索
            //通过
            $(document).on("click", "#dabiO1", function () {
                var Binas = $("#txtdan").val()
                var Name = $("#Login_N").text()
                var Njism = "S";
                $.ajax({
                    url: '/ShenPI/Index',
                    type: 'POST',
                    data: { "stetede": 1, "bians": Binas, "Namesed": Name, "Njism": Njism },
                    success: function (data) {
                        console.log(data)
                        if (data == "审批成功") {
                            var mbr = $("#JNKMHNB").text()
                            var name = $("#Login_N").text()
                            var BZJG = [];
                            BZJG.push({
                                Fr_fl: "物料核价审批",//待处理模块
                                De_tiji: "物料核价通过请继续",//待处理内容
                                Cl_juli: mbr,//接收人
                                Nd_jiage: name,//发起人
                                Fr_zhuang: "待处理"//装态
                            })
                            console.log("共" + BZJG.length + "数据");
                            console.log(BZJG);
                            $.ajax({
                                url: "/Contracts/Addfr",
                                type: 'POST',
                                data: JSON.stringify(BZJG),
                                contentType: "application/json;charset=utf-8",
                                dataType: "json",
                                success: function (text) {
                                    alert(text)
                                    window.location.href = "/Admin/shenpiView";
                                },
                                error: function (text) {
                                    alert("系统错误" + text);
                                }
                            })
                        }
                        else {
                            alert(data)
                            //window.location.href = "/Admin/shenpiView";
                        }
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            })

            //完成
            $(document).on("click", "#dabokjj", function () {

                var Binas = $("#txtdan").val()
                console.log(Binas)
                $.ajax({
                    url: '/ShenPI/HJSP',
                    type: 'POST',
                    data: { "state": 4, "bians": Binas },
                    success: function (data) {
                        //返回是否是他审批
                        alert(data)
                        window.location.href = "/Admin/shenpiView";
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            })
            $("#fanghui").click(function () {
                window.location.href = "/Admin/shenpiView";
            })
            //确定驳回
            $(document).on("click", "#WT_qdbh", function () {
                var Binas = $("#txtdan").val()
                var Name = $("#Login_sf").text()
                var Name1 = $("#Login_N").text()
                var MMK = $("#WT_dhly").val()
                var Njism = "S";
                if (MMK != "") {
                    $.ajax({
                        url: '/ShenPI/Index',
                        type: 'POST',
                        data: { "stetede": 2, "bians": Binas, "Namesed": Name, "liyou": MMK, "Njism": Njism, "Name1": Name1 },
                        success: function (data) {
                            console.log(data)
                            if (data != "驳回通过") {
                                alert(data)
                            } else {
                                alert("已驳回到采购核价！")
                                window.location.href = "/Admin/shenpiView";
                            }
                        },
                        error: function () {
                            alert("系统错误!");
                        }
                    })
                } else {
                    alert("请输入理由！")
                }
            })
            //驳回按钮
            $(document).on("click", "#dabiOLP", function () {
                var Name = $("#Login_N").text()
                $("#WT_dhr").text(Name)
                $("#WT_dh_mb").show();
            })
            $(document).on("click", "#WT_qxbh", function () {
                $("#WT_dh_mb").hide();
                $("#WT_dhly").text("");
            })
            function find_inf() {
                $.ajax({
                    url: '/ShenPI/HJSP',
                    type: 'GET',
                    data: { "state": 3, "bians": bain },
                    success: function (zc) {
                        $("#Kngsjh table").remove()
                        $("#Kngsjh").append(zc)
                        //判断最小值
                        $("#Kngsjh").parent().find("tr").each(function () {
                            var shund = Number.MAX_SAFE_INTEGER;//最大值
                            $(this).children().find('span').each(function () {
                                var ZHI = $(this).parent().children().eq(0).text()
                                if (!isNaN(ZHI) && ZHI < shund) { // 如果value是一个数字且小于当前的最小值
                                    shund = ZHI; // 更新最小值
                                }
                            })
                            $(this).find('input[type="radio"]').each(function () {
                                if ($(this).prev().text() == shund) {
                                    $(this).prev().css({ "color": "#0077ff" })
                                }
                            })
                        })
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
        })
        $(function () {
            gettuz()//搜索图纸信息
            gettbz()//搜索备注信息
            //点击切换基础信息，备注信息，图纸沟通
            $(function () {
                $("#divjibeng").click(function (e) {
                    $("#divsw1").css({ "display": "block" });
                    $("#divsw2").css({ "display": "none" });
                    $("#divsw3").css({ "display": "none" });
                    $("#divsw4").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#divbeizhu").click(function (e) {
                    $("#divsw2").css({ "display": "block" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw3").css({ "display": "none" });
                    $("#divsw4").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#divtuzhi").click(function (e) {
                    $("#divsw3").css({ "display": "block" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw2").css({ "display": "none" });
                    $("#divsw4").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })

            })
            //家在哪文件呢
            $(document).on("click", "#WLcb", function () {
                $.ajax({
                    url: "/ShenPI/Wenjian",
                    type: 'POST',
                    data: { "bian": $("#txtdan").val() },
                    success: function (text) {
                        $("#WT_dh_mb2").css({ "display": "block" })
                        $("#WJ_XZLJ").append($(`<a href="/Contracts/Download_file?path=${text}" id="log_SZ" class="WT_qxbh2">下载</a>`))
                    },
                    error: function (text) {
                        alert("系统错误");
                    }
                })
            })
            $(document).on("click", ".WT_qxbh2", function () {
                $("#WT_dh_mb2").css({ "display": "none" })
                $("#WJ_XZLJ a").remove()
            })
            //写入日志
            $(document).on("click", "#RZ_tjrz", function () {
                //组合当前日期
                var sqrq = $("#date-time").text()
                var rzxx = {
                    B_Bian: $("#txtdan").val(),
                    B_BR: $('#Login_N').text(),
                    B_Date: sqrq,
                    B_bei: $('#RZ_xznr').val(),
                };
                console.log(rzxx)
                $.ajax({
                    url: "/Contracts/AddLogs",
                    type: "POST",
                    data: rzxx,
                    success: function (data) {
                        alert(data)
                        gettbz()
                    },
                    error: function (data) {
                        alert("erroer");
                    },
                })
            })
            //获取图纸信息
            function gettuz() {
                var kan = $("#txtdan").val();
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "App_ban": kan, "state": 3 },
                    success: function (sjik) {
                        $("#div3__tb tr").remove();
                        $.each(sjik, function (i, item) {
                            var x = item.De_dizhi
                            var $tr = $(`
                                            <tr class="log_tr">
                                                <td style="display:none">${item.DE_id}</td>
                                                <td>${i + 1}</td>
                                                <td>${item.De_dizhi}</td>
                                                <td>${item.De_shijian}</td>
                                                <td>${item.De_ren}</td>
                                                <td><a href="#" id="log_SC">删除</a>/<a href="/Contracts/Download_file?path=${x}" id="log_SZ">下载</a></td>
                                            </tr>
                                            `);
                            $("#div3__tb").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }
            //获取备注信息
            function gettbz() {
                var kan = $("#txtdan").val();
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "App_ban": kan, "state": 4 },
                    success: function (sjik) {
                        $("#RZ_gwzr div").remove();
                        $.each(sjik, function (i, item) {
                            var $tr = $(`<div>
                                              <div>
                                                  <span>${item.B_BR}</span>         <span>${item.B_Date}</span>
                                                </div>
                                                 <div> ${item.B_bei}</div>
                                              </div>`);
                            $("#RZ_gwzr").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }
           
        })
    </script>

}
